package com.cangshukj.web.controller.junong;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cangshukj.common.annotation.Log;
import com.cangshukj.common.core.controller.BaseController;
import com.cangshukj.common.core.domain.AjaxResult;
import com.cangshukj.common.enums.BusinessType;
import com.cangshukj.junong.domain.ProductTypes;
import com.cangshukj.junong.service.IProductTypesService;
import com.cangshukj.common.utils.poi.ExcelUtil;
import com.cangshukj.common.core.page.TableDataInfo;

/**
 * 农产品分类Controller
 * 
 * @author wangjie
 * @date 2025-04-01
 */
@Api(value = "/product/types",description = "农产品分类")
@RestController
@RequestMapping("/product/types")
public class ProductTypesController extends BaseController
{
    @Autowired
    private IProductTypesService productTypesService;

    /**
     * 查询农产品分类列表
     */
    @ApiOperation("查询农产品分类列表")
    @PreAuthorize("@ss.hasPermi('product:types:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductTypes productTypes)
    {
        startPage();
        List<ProductTypes> list = productTypesService.selectProductTypesList(productTypes);
        clearPage();
        return getDataTable(list);
    }


    /**
     * 查询农产品分类列表(不分页)
     */
    @ApiOperation("查询农产品分类列表(不分页)")
    @GetMapping("/listNoPage")
    public AjaxResult listNoPage(ProductTypes productTypes)
    {
        List<ProductTypes> list = productTypesService.selectProductTypesList(productTypes);
        return AjaxResult.success(list);
    }

    /**
     * 获取农产品分类详细信息
     */
    @ApiOperation("获取农产品分类详细信息")
    @PreAuthorize("@ss.hasPermi('product:types:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") String typeId)
    {
        return AjaxResult.success(productTypesService.selectProductTypesByTypeId(typeId));
    }

    /**
     * 新增农产品分类
     */
    @ApiOperation("新增农产品分类")
    @PreAuthorize("@ss.hasPermi('product:types:add')")
    @Log(title = "农产品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductTypes productTypes)
    {
        productTypes.setCreateBy(getUsername());
        productTypes.setCreateTime(new Date());
        return toAjax(productTypesService.insertProductTypes(productTypes));
    }

    /**
     * 修改农产品分类
     */
    @ApiOperation("修改农产品分类")
    @PreAuthorize("@ss.hasPermi('product:types:edit')")
    @Log(title = "农产品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductTypes productTypes)
    {
        productTypes.setUpdateBy(getUsername());
        productTypes.setUpdateTime(new Date());
        return toAjax(productTypesService.updateProductTypes(productTypes));
    }

    /**
     * 删除农产品分类
     */
    @ApiOperation("删除农产品分类")
    @PreAuthorize("@ss.hasPermi('product:types:remove')")
    @Log(title = "农产品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable String[] typeIds)
    {
        return toAjax(productTypesService.deleteProductTypesByTypeIds(typeIds));
    }
}
